package com.hhh.petadopt.serviceImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.AdminLostMapper;
import com.hhh.petadopt.pojo.Lost;
import com.hhh.petadopt.pojo.LostVo;
import com.hhh.petadopt.service.AdminLostService;
import com.hhh.petadopt.utils.Page;
/**
 * 失物招领管理
 * @author 杜镇声声
 *
 */
@Service
public class AdminLostServiceImpl implements AdminLostService {
	
	@Autowired
	private AdminLostMapper adminlostmapper;

	@Override
	public Page<Lost> selectPage(LostVo Vo) {
		//创建page对象
		Page<Lost> page = new Page<Lost>();
		//设置当前页显示的条数
		page.setSize(10);
		Vo.setSize(10);
		if(null != Vo) {
			//设置当前页
			if(null != Vo.getPage()) {
				page.setPage(Vo.getPage());
				//设置起始页
				Vo.setStartRow((Vo.getPage()-1)*Vo.getSize());
			}
			if(null != Vo.getSexx() && !"".equals(Vo.getSexx().trim())) {
				Vo.setSexx(Vo.getSexx().trim());
			}
			if(null != Vo.getAdresss() && !"".equals(Vo.getAdresss().trim())) {
				Vo.setAdresss(Vo.getAdresss().trim());
			}
			if(null != Vo.getDatee() && !"".equals(Vo.getDatee())) {
				Vo.setDatee(Vo.getDatee());
			}
			//根据条件查询符合条件的总条数
			page.setTotal(adminlostmapper.selectTotal(Vo));
			//封装符合条件的当前页数据
			List<Lost> selectLostList = adminlostmapper.selectLostList(Vo);
			List<Lost> llist = new ArrayList<Lost>();
			for (Lost lost : selectLostList) {
				lost.setLosttime(lost.getLosttime().substring(0, 10));
				llist.add(lost);
			}
			page.setRows(llist);
		}
		return page;
	}

	//编辑页面信息回显
	@Override
	public Lost selectLostById(Integer id) {
		Lost selectLostById = adminlostmapper.selectLostById(id);
		
		selectLostById.setLosttime(selectLostById.getLosttime().substring(0, 10));
		return selectLostById;
	}

	//修改
	@Override
	public void updateLost(Lost lost) {
		//补全信息
		lost.setCreatedd(new Date());
		lost.setUpdated(new Date());
		//执行操作
		adminlostmapper.editLost(lost);
		
	}

	//添加失物招领信息
	@Override
	public void addLost(Lost lost) {
		//补全信息
		lost.setLoststatus("1");  //1表示发布,2表示不发布
		lost.setCreatedd(new Date());
		lost.setUpdated(new Date());
		adminlostmapper.addlost(lost);
	}

	//删除
	@Override
	public void deleteLostById(Integer id) {
		adminlostmapper.deleteLostById(id);
		
	}

	//删除多选
	@Override
	public void deleteLostsByIds(Integer[] ids) {
		adminlostmapper.deleteLostsByIds(ids);
		
	}

}
